function targetCvgBatch {
    echo -e "\033[1mSubmitting targetCvgBatch Jobs \033[0m"
    mkdir -p $STAT_DIR
    export GATK_THREADS=2

	$SUB -N cvgBatch \
	      $SUBARGS -l h_vmem=3G -pe $PE $GATK_THREADS -v GATK_THREADS,BAM_DIR \
	      "$CMD_DIR/depthOfCoverageBatch.sh" $TARGET "$STAT_DIR/batch_target_cvg"
}

function flank_coverage {
    echo -e "\033[1mSubmitting flank_coverage Jobs \033[0m"
    mkdir -p $STAT_DIR
    HOLDJID="recalTableFULL${LINE}"
    export GATK_THREADS=4
    if [ -z $SNPDB ];then
      INFILE="s_${LINE}_nodup_uniq.bam"
      HOLDJID="dedupNIndexBam${LINE}"
    else
      INFILE="s_${LINE}_nodup_uniq_recal.FULL.bam"
    fi
	$SUB -hold_jid $HOLDJID -N cvgUqF$LINE \
	      $SUBARGS -l h_vmem=2.1G -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverage.sh" "$STAT_DIR/s_${LINE}_nodup_uniq_recal_flank${2}" "$INFILE" $1
 }

function genome_coverage_merge {
    echo -e "\033[1mSubmitting genome_coverage_merge Jobs \033[0m"
    mkdir -p $STAT_DIR
    local HOLDJID="mergeChrTable_realn${LINE}"
    export GATK_THREADS=4
    
	$SUB -hold_jid $HOLDJID -N cvgUqG$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G \
               -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_nodup_uniq_recal_merge" "s_${LINE}_merged_nodup_uniq_realn_recal.bam"
}
function genome_coverage {
    echo -e "\033[1mSubmitting genome_coverage Jobs \033[0m"
    mkdir -p $STAT_DIR
    export GATK_THREADS=4
    if [ -z $SNPDB ];then
      INFILE="s_${LINE}_nodup_uniq.bam"
      HOLDJID="dedupNIndexBam${LINE}"
    else
      INFILE="s_${LINE}_nodup_uniq_recal.FULL.bam"
      HOLDJID="recalTableFULL${LINE}"
    fi
	$SUB -hold_jid $HOLDJID -N cvgUqG$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G \
               -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_nodup_uniq_recal_genome" "$INFILE"
    
 	$SUB -hold_jid $HOLDJID -N cvgNdG$LINE \
 	      $SUBARGS -l h_stack=20m,h_vmem=2G \
                -pe $PE $GATK_THREADS -v GATK_THREADS \
 	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_nodup_genome" "s_${LINE}_nodup.bam"

	$SUB -hold_jid $HOLDJID -N cvgG$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G \
              -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_genome" "s_${LINE}.bam"
 }

function stat0 {
    echo -e "\033[1mSubmitting stat0 Jobs \033[0m"
    mkdir -p $STAT_DIR
    HOLDJID="recalTableFULL${LINE}"
    export GATK_THREADS=4
    if [ -z $SNPDB ];then
      HOLDJID="dedupNIndexBam${LINE}"
    fi

    $SUB -hold_jid $HOLDJID -N cvgNdG$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G \
               -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_nodup_genome" "s_${LINE}_nodup.bam"

    $SUB -hold_jid $HOLDJID -N cvgG$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G \
              -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_genome" "s_${LINE}.bam"

    if [ ! -z $TARGET ];then
	$SUB -hold_jid $HOLDJID -N cvgNdT$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverage.sh" "$STAT_DIR/s_${LINE}_nodup_target" "s_${LINE}_nodup.bam" $TARGET

	$SUB -hold_jid $HOLDJID -N cvgT$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverage.sh" "$STAT_DIR/s_${LINE}_target" "s_${LINE}.bam" $TARGET
    fi
 }

function stat1 {
    echo -e "\033[1mSubmitting stat1 Jobs \033[0m"
    mkdir -p $STAT_DIR
    HOLDJID="recalTableFULL${LINE}"
    export GATK_THREADS=4
    if [ -z $SNPDB ];then
      INFILE="s_${LINE}_nodup_uniq.bam"
      HOLDJID="dedupNIndexBam${LINE}"    
    else
      INFILE="s_${LINE}_nodup_uniq_recal.FULL.bam"
    fi

    $SUB -hold_jid $HOLDJID -N cvgUqG_stat1_$LINE \
	      $SUBARGS -l h_vmem=6.5G \
               -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverageGenome.sh" "$STAT_DIR/s_${LINE}_nodup_uniq_recal_genome" "$INFILE"

    if [ ! -z $TARGET ];then
	$SUB -hold_jid $HOLDJID -N cvgUqT_stat1_$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverage.sh" "$STAT_DIR/s_${LINE}_nodup_uniq_recal_target" "$INFILE" $TARGET
    fi
    if [ ! -z $FLANK ];then
	$SUB -hold_jid $HOLDJID -N cvgUqF_stat1_$LINE \
	      $SUBARGS -l h_stack=20m,h_vmem=2G -pe $PE $GATK_THREADS -v GATK_THREADS \
	      "$CMD_DIR/depthOfCoverage.sh" "$STAT_DIR/s_${LINE}_nodup_uniq_recal_flank" "$INFILE" $FLANK
    fi
 }

function stat2 {
    echo -e "\033[1mSubmitting stat2 Jobs \033[0m"
    mkdir -p $STAT_DIR
    HOLDJID="recalTableFULL${LINE}"
    if [ -z $SNPDB ];then
      INFILE="s_${LINE}_nodup_uniq.bam"
      HOLDJID="dedupNIndexBam${LINE}"
    else
      INFILE="s_${LINE}_nodup_uniq_recal.FULL.bam"
    fi

    $SUB -hold_jid $HOLDJID -N meanQbycycle${LINE} \
	      $SUBARGS -l h_vmem=8G \
	      "$CMD_DIR/meanQbycycle.sh" "$INFILE" "qualityByCycle_${LINE}.pdf"
	      
    $SUB -hold_jid $HOLDJID -N meanQScDis${LINE} \
	      $SUBARGS -l h_vmem=6G \
	      "$CMD_DIR/meanQScDis.sh" "$INFILE" "quality_filter_score_${LINE}.pdf"
	      
    $SUB -hold_jid $HOLDJID -N hsMetrics${LINE} \
	      $SUBARGS -l h_vmem=6G \
	      "$CMD_DIR/hsMetrics.sh" "$INFILE" "Gc_bias_${LINE}.pdf"
	      
    $SUB -hold_jid $HOLDJID -N insertSize${LINE} \
	      $SUBARGS -l h_vmem=8G \
	      "$CMD_DIR/collectInsertSizeMetrics.sh" "$INFILE" "hst_Insert_${LINE}.pdf"
}

function variantCallBatch {
    echo -e "\033[1mSubmitting variantCallBatch1 Jobs \033[0m"
    mkdir -p vcf
    export GATK_THREADS=12

    $SUB -N varcalBatch$LINE \
	     $SUBARGS -pe $PE $GATK_THREADS -v GATK_THREADS,BAM_DIR -l h_vmem=7G \
	     "$CMD_DIR/variantCalBatch.sh" vcf ${LINE} $TARGET ${mbq} ${mmq}
#parallel environment:  DJ range: 12
#usage    1:                 cpu=19:23:54:40, mem=14986058.28825 GBs, io=983.17376, vmem=8.775G, maxvmem=8.775G
	     
    $SUB -hold_jid varcalBatch$LINE -N snpFiltr$LINE \
	     $SUBARGS -l h_stack=512m,h_vmem=7G \
	     "$CMD_DIR/variantFiltrationNoMask.sh" "${LINE}_mbq_${mbq}_mmq_${mmq}" vcf
#	     "$CMD_DIR/variantFiltration.sh" "${LINE}_mbq_${mbq}_mmq_${mmq}" vcf
	     
    $SUB -hold_jid snpFiltr${LINE} -N snpEff${LINE}  \
             $SUBARGS -l h_stack=512m,h_vmem=7G \
             "$CMD_DIR/snpEff.sh" "vcf/${LINE}_mbq_${mbq}_mmq_${mmq}_filtered_nomask"

    $SUB -hold_jid snpFiltr${LINE} -N snpEval$LINE \
	     $SUBARGS -l h_stack=512m,h_vmem=7G \
	     "$CMD_DIR/variantEval.sh" "${LINE}_mbq_${mbq}_mmq_${mmq}_filtered_nomask" vcf $TARGET
#	     "$CMD_DIR/variantEval.sh" "${LINE}_mbq_${mbq}_mmq_${mmq}_filtered" vcf $TARGET
}

function variantFiltrAlacarte {
    if [ -z $1 ];then
    	echo -e "Usage: \033[1m -t \"variantFiltrAlacarte vcffile\" \033[0m (no .vcf)"
    	exit 100
    else
    	echo -e "\033[1mSubmitting variantFiltrAlacarte $1\033[0m"
    fi

    export GATK_THREADS=4

    $SUB -N snpFiltr$LINE \
	     $SUBARGS -l h_vmem=10G \
	     "$CMD_DIR/variantFiltrAlacarte.sh" $1
}

function snpAnnotAlacarte {
    if [ -z $1 ];then
    	echo -e "Usage: \033[1m snpAnnotAlacarte vcffile \033[0m (no .vcf)"
    	exit 100
    else
    	echo -e "\033[1mSubmitting snpAnnotAlacarte $1\033[0m"
    fi

    $SUB -N snpEff${LINE}  \
             $SUBARGS -l h_stack=64m,h_vmem=7G \
             "$CMD_DIR/snpEff.sh" $1
}
